package com.cmf.enums;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

/**
 * @Author: cmf
 * @Date: 2025/8/27 16:25
 * @Version: v1.0.0
 * @Description: 系统响应状态码枚举
 **/
@Getter
public enum ResultCodeType {
    // 成功
    SUCCESS(200, "成功"),
    
    // 客户端错误 (4xx)
    BAD_REQUEST(400, "请求参数错误"),
    UNAUTHORIZED(401, "未授权"),
    FORBIDDEN(403, "无权限访问"),
    NOT_FOUND(404, "资源不存在"),
    METHOD_NOT_ALLOWED(405, "请求方法不允许"),
    CONFLICT(409, "资源冲突"),
    PARAM_MISSING(412, "参数缺失"),
    PARAM_TYPE_ERROR(413, "参数类型错误"),
    PARAM_BIND_ERROR(414, "参数绑定错误"),
    PARAM_VALID_ERROR(415, "参数校验错误"),
    
    // 服务端错误 (5xx)
    INTERNAL_SERVER_ERROR(500, "服务器内部错误"),
    SERVICE_UNAVAILABLE(503, "服务不可用"),
    
    // 业务错误 (6xx)
    BUSINESS_ERROR(600, "业务处理异常"),
    USER_NOT_EXIST(601, "用户不存在"),
    USER_ACCOUNT_LOCKED(602, "账号已被锁定"),
    USER_ACCOUNT_INVALID(603, "账号已作废"),
    
    // 数据错误 (7xx)
    DATA_NOT_FOUND(700, "数据不存在"),
    DATA_ALREADY_EXIST(701, "数据已存在"),
    DATA_ADD_FAILED(702, "数据添加失败"),
    DATA_UPDATE_FAILED(703, "数据更新失败"),
    DATA_DELETE_FAILED(704, "数据删除失败"),
    
    // 系统错误 (9xx)
    SYSTEM_ERROR(900, "系统异常"),
    UNKNOWN_ERROR(999, "未知错误");

    // 枚举值
    @EnumValue
    // 序列化时返回给前端的值
    @JsonValue
    private final Integer code;
    private final String desc;

    ResultCodeType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }
}
